package com.byzx.wine.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.byzx.wine.dao.WinetypeMapper;
import com.byzx.wine.jdbcdao.WinetypeDao;

import com.byzx.wine.po.Winetype;
import com.byzx.wine.service.IWineTypeService;
import com.byzx.wine.util.Page;

@Service
public class WinetypeService implements IWineTypeService {
	@Autowired
	private WinetypeDao winetypedao;
	@Autowired
	private WinetypeMapper winetypemapper;

	@Override
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return winetypemapper.deleteByPrimaryKey(id);
	}

	@Override
	public Map<String, Object> selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		Winetype se = winetypemapper.selectByPrimaryKey(id);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("se", se);
		return map;
	}

	@Override
	public int insert(Winetype record) {
		// TODO Auto-generated method stub
		return winetypemapper.insert(record);
	}

	@Override
	public Page<Map<String, Object>> findPage(Page<Map<String, Object>> page) {
		String sqlid = "com.byzx.wine.jdbcdao.WinetypeDao.SelectAll";
		return winetypedao.findPage(sqlid, page);
	}

	@Override
	public int updateByPrimaryKey(Winetype record) {
		// TODO Auto-generated method stub
		return winetypemapper.updateByPrimaryKey(record);
	}

	@Override
	public boolean deleteAll(String ids) {
		try {
			String[] wines = ids.split(",");
			for (int i = 0; i < wines.length; i++) {

				int id = Integer.parseInt(wines[i]);
				winetypemapper.deleteByPrimaryKey(id);
			}
			return true;
		} catch (Exception e) {
			return false;
		}
	}

}
